<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/14
 * Time: 9:27
 */

namespace app\admin\controller;


use app\admin\model\GoodsList;
use app\admin\model\GoodsSpike;
use app\admin\model\HomeAdvertisement;

class Spike extends Base
{

    public function spikeList(){
        return $this->fetch();
    }
    public function spikeData($page,$limit){
        $where = input('get.where')?[['group_title','like','%'.trim(input('get.where')).'%']]:'';
        $data = GoodsSpike::where($where)->page($page,$limit)->select()->toArray();
        $count = GoodsSpike::where($where)->count();
        $result = [
            'code'=>0,
            'msg'=>'返回成功',
            'count'=>$count,
            'data'=>$data
        ];
        return json($result);
    }

    public function spikeAdd(){
        if (request()->isPost()){
            $post = input('post.');
        }
        $data = GoodsList::where('status',1)->field('id,good_name')->select();
        $this->assign('good',$data);
        return $this->fetch();
    }

    //秒杀页面广告
    public function spikeAdvertisement(){
        return $this->fetch();
    }
    public function spikeAdvertisementData($page,$limit){
        $data = HomeAdvertisement::where('id',4)->page($page,$limit)->select()->toArray();
        $count = HomeAdvertisement::count();
        $result = [
            'code'=>0,
            'msg'=>'返回成功',
            'count'=>$count,
            'data'=>$data
        ];
        return json($result);
    }

    public function spikeAdvertisementEdit($id){
        if (request()->isPost()){
            $post = input('post.');
            $ide = $post['id'];
            $data = [
                'title'=>$post['title'],
                'image'=>$post['image'],
                'url'=>$post['url']
            ];
            $ret = HomeAdvertisement::update($data,['id'=>$ide]);
            if (!$ret){
                return json(['code'=>0,'msg'=>'保存失败']);
            }
            return json(['code'=>1,'msg'=>'保存成功']);
        }
        $data = HomeAdvertisement::where('id',$id)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }

}